home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / sc3x00 / connopen.c next >
Text File  |  1996-07-10  |  5KB  |  143 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      connopen.c                                            ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface for the GetConnectionsOpen     ║
  6. //   ║              Files API, obviously it requires the NetWare Shell.   ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ╚════════════════════════════════════════════════════════════════════╝
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <conio.h>
  25.  
  26. #include "nwsys.h"
  27.  
  28. //
  29. //  First of all, we define the request and reply structures which are
  30. //  needed for the GetConnectionsOpenFiles API call.  These structures are
  31. //  layed out according to the System Call documentation.
  32. //
  33.  
  34. struct  {
  35.     WORD    sflen;          // length of the structure.  This is 6 + 'onlen'
  36.     BYTE    sfcode;         // the subfunction code, in our case 53.
  37.     WORD    connNumber;     // object type (hi-lo)
  38.     WORD    lastRecordSeen; // length of name (below)
  39. }Request;
  40.  
  41. struct fileStruct{
  42.     WORD    taskNumber;     // task number within ws holding file open
  43.     BYTE    lockType;       // lock type  ie sharable, logged, locked, TTS
  44.     BYTE    accessControl;  // connectiosn access rights to file
  45.     BYTE    lockFlag;       // lock flag
  46.     BYTE    volumeNumber;   // volume number file resides upon
  47.     BYTE    reserved[9];
  48.     BYTE    nameSpace;      // name space identifier
  49.     BYTE    fileName[14];   // name of file (null terminated)
  50. } ;
  51.  
  52. struct     fileStruct *fs[29];
  53. int    numOpenFiles;
  54. WORD    connectionNumber;
  55.  
  56. struct  {
  57.     WORD    nextRequestRec; // next record to be requested.
  58.     WORD    numberReturned; // numober of records returned
  59.     BYTE    buffer[512];
  60. }Reply;
  61.  
  62. void ProcessEntries(void);
  63. void FreeEntries(void);
  64. void DisplayData(void);
  65. //  This routine allocates memory for the data returned for each file.
  66. //  It also makes the GetConnectionOpenFiles call and parses the data
  67. //  for each file.
  68. //
  69. void ProcessEntries(void)
  70. {
  71.     char *lookup;
  72.     int i,j;
  73.  
  74.     lookup=(char *)&Reply.buffer;
  75.     numOpenFiles=Reply.numberReturned;
  76.     for(i=0;i < numOpenFiles; i++) {
  77.         fs[i]=malloc(sizeof (struct fileStruct));
  78.         memmove((char *)&fs[i]->taskNumber,(lookup),2);
  79.         fs[i]->lockType=*(lookup+2);
  80.         fs[i]->accessControl=*(lookup+3);
  81.         fs[i]->lockFlag=*(lookup+4);
  82.         fs[i]->volumeNumber=*(lookup+5);
  83.         memmove(fs[i]->reserved,(lookup+6),9);
  84.         fs[i]->nameSpace=*(lookup+15);
  85.         for(j=0;j<*(lookup+16);j++)
  86.             fs[i]->fileName[j]=*(lookup+17+j);
  87.         fs[i]->fileName[j]='\0';
  88.         lookup=(lookup+17+j);
  89.     }
  90. }
  91.  
  92. //
  93. //  This routine frees memory allocated by ProcessEntries.
  94. //
  95. void FreeEntries( void )
  96. {
  97.     int i;
  98.  
  99.     for(i=0;i<numOpenFiles;i++)
  100.         free(fs[i]);
  101. }
  102.  
  103. //
  104. //  Display the list of open files for the connection.
  105. //
  106. void DisplayData( void )
  107. {
  108.     int i;
  109.  
  110.     clrscr();
  111.     printf("\n\nList Of %d Open Files For Connection %d\n\n",
  112.                 numOpenFiles,
  113.                 connectionNumber);
  114.     for(i=0;i<numOpenFiles;i++)
  115.         printf("%s\n",&fs[i]->fileName);
  116. }
  117. //
  118. //  This is the main program.  The purpose is to make the GetBinderyObjectID
  119. //  API call to illustrate making system calls using the F2 interface.
  120. //
  121.  
  122.  
  123. void main(int argc, char *argv[])
  124. {
  125.     int     cc;
  126.     if(argc!=2){printf("usage: CONNOPEN connectionNumber\n");exit(1);}
  127.     connectionNumber=atoi(argv[1]);
  128.     //
  129.     //  Build the request buffer
  130.     //
  131.     Request.sflen = (sizeof Request) ;
  132.     Request.sfcode = 235;                       // subfunction code
  133.     Request.connNumber = connectionNumber;
  134.     Request.lastRecordSeen = 0;
  135.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  136.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  137.     if( cc == 0 ) {
  138.         ProcessEntries();
  139.         DisplayData();
  140.         FreeEntries();
  141.     }
  142. }
  143.